package com.hackordie.operations.queries;

import com.hackordie.commons.HackOrDieResult;
import com.hackordie.exceptions.HackOrDieException;
import com.hackordie.operations.AHackOrDieOperationComputerType;

public class QueryComputerType extends AHackOrDieOperationComputerType {

	private final String computerTypeName;
	private final int computerTypeId;
	private final int first;
	private final int last;
	private final boolean allComponentsType;
	
	public QueryComputerType(String computerTypeName) {
		super();
		this.computerTypeName = computerTypeName;
		this.computerTypeId = -1;
		this.first = -1;
		this.last = -1;
		this.allComponentsType = false;
	}
	
	public QueryComputerType(int  computerTypeId) {
        super();
        this.computerTypeName = "";
        this.computerTypeId = computerTypeId;
        this.first = -1;
        this.last = -1;
        this.allComponentsType = false;

    }
	
	public QueryComputerType(int first, int last) {
	    this.computerTypeName = "";
        this.computerTypeId = -1;
	    this.first = first;
        this.last = last;
        this.allComponentsType = false;
    }

    public QueryComputerType() {
        this.computerTypeName = "";
        this.computerTypeId = -1;
        this.first = -1;
        this.last = -1;
        this.allComponentsType = true;
    }

    @Override
	protected boolean checkParameters() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	protected HackOrDieResult executeOperation() throws HackOrDieException {

        if (allComponentsType) {
            result.setObject(computerTypeDao.getAll());
        } else {
            if (first > -1) {
                result.setObject(computerTypeDao.getByRange(first, last));
            } else {
                if (computerTypeId == -1) {
                    result.setObject(computerTypeDao.get(computerTypeName));
                } else {
                    result.setObject(computerTypeDao.get(computerTypeId));
                }
            }
        }
        return result;
    }
}
